#include "Protocols/ShowableItem.h"
#include "protocols/PacketInfo.h"
#include "utilities/ReadablePacket.h"
#include "protocols/ProtocalCode.h"
#include "protocols/ProtocalPool.h"
#include <time.h>

REGISTER_PROTOCOL(Summary)

using boost::shared_ptr;

void PacketInfoHeader::toShowableItems(ShowableItem* root) const{
	int pos = mPos;
	ShowableItem* tmp,*flag;

	ShowableItem* proto = createProtocalItem("Packet Info",
		mPos,getHeaderLength());
	root->pushChild(proto);

	tmp = createItemUnchange("Packet Number:",QString::number(packet->getId()),"",pos,0);
	proto->pushChild(tmp);

	tmp = createItemUnchange("Packet Length:",QString::number(packet->getLength())+"bytes","",pos,0);
	proto->pushChild(tmp);

	tmp = createItemUnchange("Packet CapLength:",QString::number(packet->getCapLength())+"bytes","",pos,0);
	proto->pushChild(tmp);

	timeval tmp_time =packet->getTStamp();
	time_t tmp_t = tmp_time.tv_sec;
	tm* t =	localtime((const time_t *)&tmp_t);

	QString time = QString::number(t->tm_hour)+":"+QString::number(t->tm_min)+":"+QString::number(t->tm_sec)+"."+QString::number(tmp_time.tv_usec)+"   "+QString::number(t->tm_mday)+"/"+QString::number(t->tm_mon+1)+"/"+QString::number(t->tm_year+1900);
	tmp = createItemUnchange("Timestamp:",time,"",pos,0);
	proto->pushChild(tmp);
} 
Summary::Summary():Protocol(SUMMARY,QString("SUMMARY"))
{
}

PacketHeader*
Summary::analyzeProc(ReadablePacket* packet,int low,int high,Protocol*& tip)
{
	PacketInfoHeader* header = new PacketInfoHeader(PROTOCOL_POINTER(Summary),packet->getData(),low,high - low + 1);
	header->getPacket(packet);
	tip = NULL;

	return header;
}